package com.lcm.weam.controller.sys;


import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSSException;
import com.lcm.weam.entity.resp.Result;
import com.lcm.weam.entity.resp.ResultCode;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

/**
 * 全局的异常捕获处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 捕获@requireXXX发送的AuthorizationException
     */
    @ExceptionHandler(AuthorizationException.class)
    public Result unauthorized(AuthorizationException e){
        e.printStackTrace();
        return new Result(ResultCode.UNAUTHORISE);
    }

    @ExceptionHandler(IOException.class)
    public Result ioError(IOException e){
        e.printStackTrace();
        return new Result(ResultCode.SERVER_ERROR);
    }

    @ExceptionHandler(ClientException.class)
    public Result ossClientException(ClientException e){
        e.printStackTrace();
        return new Result(ResultCode.OSS_CLIENT_ERROR);
    }

    @ExceptionHandler(OSSException.class)
    public Result ossException(OSSException e){
        e.printStackTrace();
        return new Result(ResultCode.OSS_SERVER_ERROR);
    }
}
